/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved.
 * Description: MMKV for Cangjie API
 * Author: xwx1230846
 * Create: 2023-04-12
 * Notes: 2023-04-12 Create
 */

#include "MMKVPredef.h"
#include "MMBuffer.h"
#include "MMKV.h"
#include "MMKVLog.h"
#include "MemoryFile.h"
#include <stdint.h>
#include <string.h>

#ifdef __cplusplus
extern "C" {
#endif

#ifndef _WIN32
extern int memcpy_s(void *dest, uint32_t destsz, const void *src, uint32_t count);
extern int strcpy_s(char *dest, uint32_t destsz, const char *src);
#endif

typedef struct {
    size_t len;
    void *data;
}byteArray;

typedef struct {
    size_t size;
    union data_t {
        byteArray *byteArrayData;
        char *charArrayData;
    }data[1];
}DataList;

typedef void (*LogHandler4Cj)(MMKVLogLevel level, const char *file, int line, const char *function,
                              const char *message);
typedef MMKVRecoverStrategic (*ErrorHandler4Cj)(const char *mmapID);
typedef void (*ContentChangeHandler4Cj)(const char *mmapID);

typedef struct {
    LogHandler4Cj logHandler;
    ErrorHandler4Cj onMMKVCRCCheckFail;
    ErrorHandler4Cj onMMKVFileLengthError;
    ContentChangeHandler4Cj onMMKVContentChange;
}MMKVHandler;

extern int64_t getSizeofSize_t();

#ifdef __cplusplus
}
#endif